package com.example.springboot2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.util.unit.DataSize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.MultipartConfigElement;

@Controller
@SpringBootApplication
public class Springboot2Application {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World";
    }

    public static void main(String[] args) {
        //如果想要关闭banner
        SpringApplication.run(Springboot2Application.class, args);
    }


    //在jar包运行web项目的文件上传和访问处理
    //简介:讲解在spring boot运行方式 java -jar 图片上传和访问
    //文件大小配置，启动类里面配置
    @Bean
    public MultipartConfigElement multipartConfigElement() {

        MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();

        //单个文件最大
        multipartConfigFactory.setMaxFileSize(DataSize.parse("1024KB"));
        //设置总上传数据的大小
        multipartConfigFactory.setMaxRequestSize(DataSize.parse("1024000KB"));
        return multipartConfigFactory.createMultipartConfig();


    }

}
